package com.jiangyg.devtools.execute.code.parser;

import com.jiangyg.devtools.entity.code.BeanProperty;
import com.jiangyg.devtools.toolkit.Assert;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 类描述：简单的 Bean 属性解析器
 *
 * @author jiangyg
 * @version 1.0
 * @date 2023年09月22日
 */
public class SimpleBeanPropertyParser extends AbstractPropertyParser {

    public SimpleBeanPropertyParser(String input) {
        super(input);
    }

    @Override
    protected List<BeanProperty> parseBeanPropertyList() throws IOException {
        final List<BeanProperty> props = new ArrayList<>();

        readByLine(this.input, line -> {
            final String[] split = line.trim().split(separator);
            Assert.state(split.length > 0);

            final String name = split[0];
            final String type = split.length > 1 ? split[1] : StringUtils.EMPTY;
            final String comment = split.length > 2 ? split[2] : StringUtils.EMPTY;

            final BeanProperty prop = buildBeanProperty(name, type, comment);
            props.add(prop);
        });

        return props;
    }

    @Override
    public boolean support() {
        return true;
    }

}
